 package com.hongdee.poi;

 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler.SheetContentsHandler;

 import java.util.LinkedHashMap;

 public class ExcelWorkSheetRowCallbackHandler
   implements SheetContentsHandler
 {
   private static final Log LOG = LogFactory.getLog(ExcelWorkSheetRowCallbackHandler.class);
 
   private int HEADER_ROW = 0;
   private ExcelRowContentCallback rowCallback;
   private LinkedHashMap<String, String> currentRowMap;
   private LinkedHashMap<String, String> columnHeaders;
   private int currentRow;
 
   public ExcelWorkSheetRowCallbackHandler(ExcelRowContentCallback rowCallbackHandler)
   {
     this.rowCallback = rowCallbackHandler;
   }
 
   public void setHeadRow(int hr)
   {
     this.HEADER_ROW = hr;
   }
 
   public void startRow(int rowNum)
   {
     this.currentRow = rowNum;
     if (this.currentRow < this.HEADER_ROW) {
       return;
     }
     if (this.currentRow == this.HEADER_ROW) {
       this.columnHeaders = new LinkedHashMap();
     } else {
       this.currentRowMap = new LinkedHashMap();
 
       for (String columnHeader : this.columnHeaders.values())
         this.currentRowMap.put(columnHeader, "");
     }
   }
 
   public void cell(String cellReference, String formattedValue)
   {
     if (this.currentRow < this.HEADER_ROW) {
       return;
     }
 
     if (this.currentRow == this.HEADER_ROW) {
       this.columnHeaders.put(getColumnReference(cellReference), formattedValue + getColumnReference(cellReference));
     } else {
       String columnHeader = (String)this.columnHeaders.get(getColumnReference(cellReference));
       this.currentRowMap.put(columnHeader, formattedValue);
     }
   }
 
   public void endRow()
   {
     if (this.currentRow <= this.HEADER_ROW) return;
     try {
       LOG.debug("rowNum=" + this.currentRow + ", map=" + this.currentRowMap);
 
       this.rowCallback.processRow(this.currentRow, this.currentRowMap);
     } catch (Exception e) {
       throw new RuntimeException("Error invoking callback", e);
     }
   }
 
   public void headerFooter(String text, boolean isHeader, String tagName)
   {
   }
 
   private String getColumnReference(String cellReference)
   {
     if (StringUtils.isBlank(cellReference)) {
       return "";
     }
 
     return cellReference.split("[0-9]*$")[0];
   }
 }

/* Location:           D:\Documents\Downloads\classes\classes\
 * Qualified Name:     com.myjeeva.poi.ExcelWorkSheetRowCallbackHandler
 * JD-Core Version:    0.5.3
 */